package com.sctvcloud.zhaohua_sd.ui.adapter.holder;

import android.content.Context;
import android.view.View;
import android.widget.CompoundButton;

import com.ruihang.generalibrary.ui.adapter.holder.BaseRecylerHolder;
import com.ruihang.generalibrary.ui.util.OnItemInternalCheckChangedListener;
import com.ruihang.generalibrary.ui.widget.CustomCheckBox;
import com.sctvcloud.zhaohua_sd.R;
import com.sctvcloud.zhaohua_sd.ui.datainf.IColumnData;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2017/7/5 0005.
 */

public class AddColumnHolder<T extends IColumnData> extends BaseRecylerHolder<T> implements View.OnClickListener, CompoundButton.OnCheckedChangeListener {
    @BindView(R.id.item_add_column_cb)
    protected CustomCheckBox isSelect;
//    @ViewInject(R.id.item_add_column_name)
//    private CustomFontTextView column_name;

    public AddColumnHolder(Context context, View itemView) {
        super(context, itemView);
//        itemView.setOnClickListener(this);
    }

    @Override
    protected void initInject() {
        ButterKnife.bind(this, itemView);
        isSelect.setOnCheckedChangeListener(this);
    }

    @Override
    public void setData(T t) {
        isSelect.setText(t.getDataTitle());
        isSelect.setChecked(t.isSubscribe(), false);
//        setStationg(t.isSubscribe());
    }

    @Override
    public void onClick(View v) {
        if (internalClick != null) {
            internalClick.onItemInternalClick(itemView, v, getAdapterPosition());
        }
    }

//    @OnClick(value = {R.id.item_add_column_cb}, type = CompoundButton.OnCheckedChangeListener.class)
//    public void onCheckClick(CompoundButton button, boolean checked) {
//        if (internalCheckChangedListener != null) {
//            internalCheckChangedListener.onItemInternalCheckedChanged(itemView, button, getAdapterPosition(), checked);
//        }
//    }

    @Override
    public AddColumnHolder setInternalCheckChangedListener(OnItemInternalCheckChangedListener internalCheckChangedListener) {
        super.setInternalCheckChangedListener(internalCheckChangedListener);
        return this;
    }


    @Override
    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
        if (internalCheckChangedListener != null) {
            internalCheckChangedListener.onItemInternalCheckedChanged(itemView, buttonView, getAdapterPosition(), isChecked);
        }
    }

    private void setStationg(boolean isSubscribe) {
        if (isSubscribe) {
            // isSelect.setChecked(t.isSubscribe());
            isSelect.setTextColor(context.getResources().getColor(R.color.white));
            isSelect.setBackgroundResource(R.drawable.ucrop_bg_cv_red);
        } else {
            isSelect.setTextColor(context.getResources().getColor(R.color.colorRedMain));
            isSelect.setBackgroundResource(R.drawable.bg_look_back);
        }
    }
}
